package com.cgx.tablet.beeper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cgx.tablet.beeper.R;
import com.cgx.tablet.beeper.bean.SpecialCallBean;
import com.cgx.tablet.beeper.interfaces.OnItemClickListener;
import com.yatoooon.screenadaptation.ScreenAdapterTools;

/**
 * Created by Administrator on 2018/9/5 0005.
 */

public class SpecialCallAdapter extends BaseAdapter<SpecialCallBean> {

    private Context mContext;
    LayoutInflater mInflater;
    private OnItemClickListener onItemClickListener;

    public SpecialCallAdapter(Context context) {
        mContext = context;
        this.mInflater = LayoutInflater.from(this.mContext);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    protected View newView(Context context, int position, ViewGroup viewGroup) {
        View view = mInflater.inflate(R.layout.item_special_call, null);

        SpecialCallAdapter.ViewHolder holder = new SpecialCallAdapter.ViewHolder();
        holder.ticket = view.findViewById(R.id.ticket);
        holder.ticket_time = view.findViewById(R.id.ticket_time);
        holder.status = view.findViewById(R.id.status);
        holder.mark = view.findViewById(R.id.mark);
        holder.operate = view.findViewById(R.id.specified_call_operate);
        view.setTag(holder);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }

    @Override
    protected void bindView(View view, final int position, SpecialCallBean specialCallBean) {
        SpecialCallAdapter.ViewHolder holder = (ViewHolder) view.getTag();
        if (specialCallBean != null){
            holder.ticket.setText(specialCallBean.getTicket());
            holder.ticket_time.setText(specialCallBean.getTicketTime());
            holder.status.setText("等待中");
            holder.mark.setText("标记" + position);
            holder.operate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null)
                        onItemClickListener.onItemClick(v, position);
                }
            });
        }
    }

    @Override
    public long getItemId(int position) {
        SpecialCallBean specifiedCall = this.getItem(position);
        return specifiedCall == null ? 0L:(long)specifiedCall.hashCode();
    }

    private static class ViewHolder {
        TextView ticket;
        TextView ticket_time;
        TextView status;
        TextView mark;
        TextView operate;
    }

}
